package org.jivesoftware.openfire.redischat;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import org.xmpp.packet.JID;

public class RedisMUCUser implements Serializable {
	/**
	 * 
	 */
	private static final long serialVersionUID = -3776409646738603652L;

	private JID jid;

	private List<JID> rooms = new ArrayList<JID>(); // rooms' BareJID

	public RedisMUCUser(JID jid) {
		super();
		this.jid = jid;
	}

	public JID getJid() {
		return jid;
	}

	public void setJid(JID jid) {
		this.jid = jid;
	}

	public JID[] getRoomJids() {
		return rooms.toArray(new JID[rooms.size()]);
	}

	public void joinRoom(JID roomJid) {
		if (!rooms.contains(roomJid)) {
			rooms.add(roomJid.asBareJID());
		}
	}

	public void leaveRoom(JID roomId) {
		if (rooms.contains(roomId)) {
			rooms.remove(roomId.asBareJID());
		}
	}

	//判断此用户是否在某个房间
	public boolean isInRoom(JID roomJid) {		 
		return rooms.contains(roomJid.asBareJID());
	}

}
